apiready = function() {
	var header = $api.byId('header');
    $api.fixStatusBar(header);
	
	// status bar style
    api.setStatusBarStyle({
        style: 'light'
    });

	// show main
	var width = api.winWidth;
    var headerPos = $api.offset(header);
    var height = api.winHeight - headerPos.h;
    
    api.openFrame({
        name: 'discovery-con',
        url: 'discovery-con.html',
        rect: {
            x: 0,
            y: headerPos.h,
            w: width,
            h: height
        },
        bounces: true,
        opaque: true,
        vScrollBarEnabled: false
    });
};


//search activity
var searchActOpened = false;

function closeFramGroup(){
    api.closeFrameGroup({
        name: 'searchAct'
    });

    var actLi = $api.dom('#header .activity li.active');
    $api.removeCls(actLi,'active');
    searchActOpened = false;
}

//search activity
function searchGroups(el,type){
    if(!el || !type){return;}

    var header = $api.byId('header');
    var pos = $api.offset(header);

    var index = 0;  //frame group index
    if(type === "type"){
        index = 1;
    }

    if(!searchActOpened){
        api.openFrameGroup ({
            name: 'searchAct',
            scrollEnabled: false,
            rect:{x: 0, y: pos.h, w: 'auto', h: 'auto'},
            index: index,
            frames:[{
                name: 'searchActBy-city',
                url: '../../html/searchActBy-city.html',
                bounces: false,
                opaque: false,
                bgColor: 'rgba(51,51,51,0.6)',
                vScrollBarEnabled: false
            },{
                name: 'searchActBy-type',
                url: '../../html/searchActBy-type.html',
                bounces: false,
                opaque: false,
                bgColor: 'rgba(51,51,51,0.6)',
                vScrollBarEnabled:false
            }]
        }, function(ret, err){
            
        });

        searchActOpened = true;
    }else{
        api.setFrameGroupIndex ({
            name: 'searchAct',
            index: index
            // ,scroll: true
        });
        api.setFrameGroupAttr({
            name: 'searchAct',
            hidden: false
        });
    }

    //toggle active style
    var curLi = el.parentNode;
    //close frame group
    if($api.hasCls(curLi,'active')){
        
        api.setFrameGroupAttr({
            name: 'searchAct',
            hidden: true
        });
        
    }
    $api.toggleCls(curLi,'active');

    var lis = $api.domAll('#header .activity li');
    var i = 0, len = lis.length;

    for(i; i<len; i++){
        var thisLi = lis[i];
        if(thisLi === curLi){
            continue;
        }else{
            if($api.hasCls(thisLi,'active')){
                $api.removeCls(thisLi,'active');
            }
        }
    }

}